//
//  ChexianCell.m
//  iCarStyle
//
//  Created by liunian on 13-9-17.
//  Copyright (c) 2013年 liunian. All rights reserved.
//

#import "ChexianCell.h"
#import "InsuranceDetailController.h"

@implementation ChexianCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)updateWithChexian:(ChexianItem *)item{
    [self.type setText:item.type];
    [self.actualPrice setText:[NSString stringWithFormat:@"真实价格:%@",item.artualPrice]];
    [self.marketPrice setText:[NSString stringWithFormat:@"市场价格:%@",item.marketPrice]];
    
    [self.scope setText:item.scope];
    
    CGSize size = [self.scope.text sizeWithFont:self.scope.font forWidth:300 lineBreakMode:1];
    size = [self.scope.text sizeWithFont:self.scope.font constrainedToSize:CGSizeMake(280, 1000.0f) lineBreakMode:1];
    [self.scope sizeThatFits:size];
    
    [self.scope setFrame:CGRectMake(10, CGRectGetMaxY(self.actualPrice.frame), size.width, size.height)];
    
}

#pragma mark getter
- (UILabel *)actualPrice{
    if (!_actualPrice) {
        _actualPrice = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMinX(self.type.frame),
                                                                 CGRectGetMaxY(self.type.frame) + 10,
                                                                 140, 20)];
        _actualPrice.backgroundColor = [UIColor clearColor];
        _actualPrice.textColor = [UIColor darkTextColor];
        _actualPrice.font = FONT_CONTENT(16.0f);
        [_actualPrice setNumberOfLines:1];
        [self addSubview:_actualPrice];
    }
    return _actualPrice;
}

- (UILabel *)marketPrice{
    if (!_marketPrice) {
        _marketPrice = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.actualPrice.frame),
                                                                 CGRectGetMinY(self.actualPrice.frame),
                                                                 140, 20)];
        _marketPrice.backgroundColor = [UIColor clearColor];
        _marketPrice.textColor = [UIColor darkTextColor];
        _marketPrice.font = FONT_CONTENT(16.0f);
        [_marketPrice setNumberOfLines:0];
        [self addSubview:_marketPrice];
    }
    return _marketPrice;
}

- (UILabel *)scope{
    if (!_scope) {
        _scope = [[UILabel alloc] initWithFrame:CGRectMake(10,
                                                           CGRectGetMaxY(self.actualPrice.frame)+ 10,
                                                           CGRectGetWidth(self.bounds) - 20, 40)];
        _scope.backgroundColor = [UIColor clearColor];
        _scope.textColor = [UIColor flatBlackColor];
        _scope.font = FONT_CONTENT(16.0f);
        [_scope setNumberOfLines:0];
        [_scope setLineBreakMode:1];
        [self addSubview:_scope];
    }
    return _scope;
}


- (UILabel *)type{
    if (!_type) {
        _type = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 100, 20)];
        _type.backgroundColor = [UIColor clearColor];
        _type.textColor = [UIColor darkTextColor];
        _type.font = FONT_CONTENT(22.0f);
        [_type setNumberOfLines:1];
        [self addSubview:_type];
    }
    return _type;
}

@end
